package juc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier=new CyclicBarrier(7, new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"召唤七龙珠");
            }
        });
        for (int i=1;i<=7;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {

                    try {
                        System.out.println("集齐"+Thread.currentThread().getName()+"珠");
                        cyclicBarrier.await();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    } catch (BrokenBarrierException e) {
                        throw new RuntimeException(e);
                    }
                }
            },i+"").start();
        }
    }
}
